package com.jeesite.modules.dataScreen.web;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import com.jeesite.modules.dataScreen.service.DataScreenService;
import com.jeesite.modules.dataScreen.utils.CacheUtils;
import com.jeesite.modules.dataScreen.utils.DataScreenUtils;
import com.jeesite.modules.dataScreen.web.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.*;

/**
 * 大屏数据查询api
 *
 * @author lh
 * @version 2023年5月6日
 */
@Controller
@Api("大屏数据接口")
@RequestMapping("/dataScreen")
@Slf4j
public class DataScreenApi extends BaseController {

    @Resource
    private DataScreenService dataScreenService;

    /**
     * 获取所有指标数据
     *
     * @return 结果
     */
    @RequestMapping("getAllData")
    @ResponseBody
    @ApiOperation("获取所有指标数据")
    public Result<?> getAllData() {
        List<Map<String, String>> dataScreen = DataScreenUtils.getDataScreenAllList();
        return Result.OK(Boolean.TRUE, "查询成功！", dataScreen);
    }

    /**
     * 根据模块关键字查询指标
     *
     * @param key1 模块名
     * @param key2 子模块名
     * @param key3 子子模块名
     * @return 结果
     */
    @RequestMapping("getDataByKeys")
    @ResponseBody
    @ApiOperation("根据模块关键字查询指标")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "key1", value = "关键字1"),
            @ApiImplicitParam(name = "key2", value = "关键字2"),
            @ApiImplicitParam(name = "key3", value = "关键字3")
    })
    public Result<?> getDataByKeys(String key1, String key2, String key3) {
        log.debug("查询参数 => {},{},{}", key1, key2, key3);
        List<Map<String, String>> dataScreen = DataScreenUtils.getDataScreenList(key1, key2, key3);
        return Result.OK(Boolean.TRUE, "查询成功！", dataScreen);
    }

    /**
     * 综合概览-运行动态-当前在网车辆(动态指标)
     * 畅行高速-高速运行-当前在网车辆(动态指标)
     *
     * @return 结果
     */
    @RequestMapping("getNetWorkFlowData")
    @ResponseBody
    @ApiOperation("综合概览-运行动态-当前在网车辆(动态指标) AND 畅行高速-高速运行-当前在网车辆(动态指标)")
    public Result<?> getNetWorkFlowData() {
        long                resValue = getDynamicDataByCache(DataScreenUtils.CACHE_KEY_CURRENT_NETWORK_FLOW_DATA, "1");
        Map<String, Object> map      = MapUtil.newHashMap();
        map.put("data", resValue);
        map.put("unit", "辆");
        map.put("name", "当前在网车辆");
        List<Map<String, Object>> data = new ArrayList<>();
        data.add(map);
        return Result.OK(Boolean.TRUE, "查询成功！", data);
    }

    /**
     * 综合概览-运行动态-当天高速车流量(动态指标)
     * 畅行高速-高速运行-累计车流量(动态指标)
     *
     * @return 结果
     */
    @RequestMapping("getHighWayFlowData")
    @ResponseBody
    @ApiOperation("综合概览-运行动态-当日出口流量(动态指标) AND 畅行高速-高速运行-当日出口流量(动态指标)")
    public Result<?> getHighWayFlowData() {
        long                resValue = getDynamicDataByCache(DataScreenUtils.CACHE_KEY_CURRENT_HIGHWAY_FLOW_DATA, "2");
        Map<String, Object> map      = MapUtil.newHashMap();
        map.put("data", resValue);
        map.put("unit", "辆");
        map.put("name", "当日出口流量");
        List<Map<String, Object>> data = new ArrayList<>();
        data.add(map);
        return Result.OK(Boolean.TRUE, "查询成功！", data);
    }

    /**
     * 综合概览-运行动态-出租车营收(指标)
     *
     * @return 结果
     */
    @RequestMapping("getTaxiRevenueData")
    @ResponseBody
    @ApiOperation("综合概览-运行动态-出租车营收(指标)")
    public Result<?> getTaxiRevenueData() {
        // 综合概览-运行动态-出租车营收指标
        List<Map<String, String>> data = dataScreenService.getTaxiRevenueData();
        return Result.OK(Boolean.TRUE, "查询成功！", data);
    }

    /**
     * 综合概览-运行动态-公交客流量(动态指标)
     * 运输服务-公共交通-每日公交客流量-(动态指标-公交)
     *
     * @return 结果
     */
    @RequestMapping("getBusPassengerFlowData")
    @ResponseBody
    @ApiOperation("综合概览-运行动态-公交客流量(动态指标) AND 运输服务-公共交通-每日公交客流量-动态指标(公交)")
    public Result<?> getBusPassengerFlowData() {
        long                resValue = getDynamicDataByCache(DataScreenUtils.CACHE_KEY_CURRENT_PASSENGER_FLOW_BUS_DATA, "3");
        Map<String, Object> map      = MapUtil.newHashMap();
        map.put("data", resValue);
        map.put("unit", "人次");
        map.put("name", "公交客流量");
        List<Map<String, Object>> data = new ArrayList<>();
        data.add(map);
        return Result.OK(Boolean.TRUE, "查询成功！", data);
    }

    /**
     * 综合概览-运行动态-轨道交通客流量(动态)
     *
     * @return 结果
     */
    @RequestMapping("getRailTransitFlowData")
    @ResponseBody
    @ApiOperation("综合概览-运行动态-轨道客流量(指标)")
    public Result<?> getRailTransitFlowData() {
        long                resValue = getDynamicDataByCache(DataScreenUtils.CACHE_KEY_CURRENT_RAIL_TRANSIT_FLOW_DATA, "5");
        Map<String, Object> map      = MapUtil.newHashMap();
        map.put("data", resValue);
        map.put("unit", "人次");
        map.put("name", "轨道总客流");
        List<Map<String, Object>> data = new ArrayList<>();
        data.add(map);
        return Result.OK(Boolean.TRUE, "查询成功！", data);
    }

    /**
     * 综合概览-目标任务-雷达图
     *
     * @return 结果
     */
    @RequestMapping("getTargetTaskData")
    @ResponseBody
    @ApiOperation("综合概览-目标任务-雷达图")
    public Result<?> getTargetTaskData() {
        List<Map<String, String>> data = CacheUtils.get(DataScreenUtils.CACHE_NAME_SCREEN_LIST, "CACHE_KEY_TARGET_TASK_DATA");
        if (data == null || data.isEmpty()) {
            data = dataScreenService.getTargetTaskData();
            CacheUtils.put(DataScreenUtils.CACHE_NAME_SCREEN_LIST, "CACHE_KEY_TARGET_TASK_DATA", data);
        }
        return Result.OK(Boolean.TRUE, "查询成功！", data);
    }

    /**
     * 数字公路-当年重点工程项目(列表)
     *
     * @return 结果
     */
    @RequestMapping("getHighWayImportantProjectData")
    @ResponseBody
    @ApiOperation("数字公路-当年重点工程项目(列表)")
    public Result<?> getHighWayImportantProjectData() {
        List<Map<String, String>> data = CacheUtils.get(DataScreenUtils.CACHE_NAME_SCREEN_LIST, "CACHE_KEY_HIGH_WAY_IMPORTANT_PROJECT_DATA");
        if (data == null || data.isEmpty()) {
            data = dataScreenService.getHighWayImportantProjectData();
            CacheUtils.put(DataScreenUtils.CACHE_NAME_SCREEN_LIST, "CACHE_KEY_HIGH_WAY_IMPORTANT_PROJECT_DATA", data);
        }
        return Result.OK(Boolean.TRUE, "查询成功！", data);
    }

    /**
     * 数字铁路-当年重点工程项目(列表)
     *
     * @return 结果
     */
    @RequestMapping("getRailWayImportantProjectData")
    @ResponseBody
    @ApiOperation("数字铁路-当年重点工程项目(列表)")
    public Result<?> getRailWayImportantProjectData() {
        List<Map<String, String>> data = CacheUtils.get(DataScreenUtils.CACHE_NAME_SCREEN_LIST, "CACHE_KEY_RAIL_WAY_IMPORTANT_PROJECT_DATA");
        if (data == null || data.isEmpty()) {
            data = dataScreenService.getRailWayImportantProjectData();
            CacheUtils.put(DataScreenUtils.CACHE_NAME_SCREEN_LIST, "CACHE_KEY_RAIL_WAY_IMPORTANT_PROJECT_DATA", data);
        }
        return Result.OK(Boolean.TRUE, "查询成功！", data);
    }

    /**
     * 数字港航-当年重点工程项目(列表)
     *
     * @return 结果
     */
    @RequestMapping("getWaterWayImportantProjectData")
    @ResponseBody
    @ApiOperation("数字港航-当年重点工程项目(列表)")
    public Result<?> getWaterWayImportantProjectData() {
        List<Map<String, String>> data = CacheUtils.get(DataScreenUtils.CACHE_NAME_SCREEN_LIST, "CACHE_KEY_WATER_WAY_IMPORTANT_PROJECT_DATA");
        if (data == null || data.isEmpty()) {
            data = dataScreenService.getWaterWayImportantProjectData();
            CacheUtils.put(DataScreenUtils.CACHE_NAME_SCREEN_LIST, "CACHE_KEY_WATER_WAY_IMPORTANT_PROJECT_DATA", data);
        }
        return Result.OK(Boolean.TRUE, "查询成功！", data);
    }

    /**
     * 数字民航-当年重点工程项目(列表)
     *
     * @return 结果
     */
    @RequestMapping("getAirWayImportantProjectData")
    @ResponseBody
    @ApiOperation("数字民航-当年重点工程项目(列表)")
    public Result<?> getAirWayImportantProjectData() {
        List<Map<String, String>> data = CacheUtils.get(DataScreenUtils.CACHE_NAME_SCREEN_LIST, "CACHE_KEY_AIR_WAY_IMPORTANT_PROJECT_DATA");
        if (data == null || data.isEmpty()) {
            data = dataScreenService.getAirWayImportantProjectData();
            CacheUtils.put(DataScreenUtils.CACHE_NAME_SCREEN_LIST, "CACHE_KEY_AIR_WAY_IMPORTANT_PROJECT_DATA", data);
        }
        return Result.OK(Boolean.TRUE, "查询成功！", data);
    }

    /**
     * 畅行高速-在建高速项目(列表)
     *
     * @return 结果
     */
    @RequestMapping("getHighSpeedProjectData")
    @ResponseBody
    @ApiOperation("畅行高速-在建高速项目(列表)")
    public Result<?> getHighSpeedProjectData() {
        List<Map<String, String>> data = CacheUtils.get(DataScreenUtils.CACHE_NAME_SCREEN_LIST, "CACHE_KEY_HIGH_SPEED_PROJECT_DATA");
        if (data == null || data.isEmpty()) {
            data = dataScreenService.getHighSpeedProjectData();
            CacheUtils.put(DataScreenUtils.CACHE_NAME_SCREEN_LIST, "CACHE_KEY_HIGH_SPEED_PROJECT_DATA", data);
        }
        return Result.OK(Boolean.TRUE, "查询成功！", data);
    }

    /**
     * 畅行高速-高速运行-外省入渝车流量(动态指标)
     *
     * @return 结果
     */
    @RequestMapping("getProvincialFlowData")
    @ResponseBody
    @ApiOperation("畅行高速-高速运行-外省入渝车流量(动态指标)")
    public Result<?> getProvincialFlowData() {
        long                resValue = getDynamicDataByCache(DataScreenUtils.CACHE_KEY_CURRENT_PROVINCIAL_FLOW_DATA, "4");
        Map<String, Object> map      = MapUtil.newHashMap();
        map.put("data", resValue);
        map.put("unit", "辆");
        map.put("name", "外省入渝车流量");
        List<Map<String, Object>> data = new ArrayList<>();
        data.add(map);
        return Result.OK(Boolean.TRUE, "查询成功！", data);
    }

    /**
     * 畅行高速-高速运行-路网信息、当日管制、当天统计数据(指标)
     *
     * @return 结果
     */
    @RequestMapping("getHighSpeedCurrentData")
    @ResponseBody
    @ApiOperation("畅行高速-高速运行-路网信息、当日管制、当天统计数据(指标)")
    public Result<?> getHighSpeedCurrentData() {
        Map<String, Object> cacheMap = CacheUtils.get(DataScreenUtils.CACHE_NAME_SCREEN_LIST, "CACHE_KEY_HIGH_SPEED_CURRENT_DATA");
        if (cacheMap == null || cacheMap.isEmpty()) {
            // 路网信息
            List<Map<String, Object>> lwData = dataScreenService.getHighSpeedCurrentRoadNetworkData();
            // 当日管制
            List<Map<String, Object>> gzData = dataScreenService.getHighSpeedCurrentControlData();
            // 当日统计
            List<Map<String, Object>> tjData = dataScreenService.getHighSpeedCurrentStatisticalData();
            cacheMap = MapUtil.newHashMap();
            cacheMap.put("gzData", gzData);
            cacheMap.put("tjData", tjData);
            cacheMap.put("lwData", lwData);
            CacheUtils.put(DataScreenUtils.CACHE_NAME_SCREEN_LIST, "CACHE_KEY_HIGH_SPEED_CURRENT_DATA", cacheMap);
        }
        return Result.OK(Boolean.TRUE, "查询成功！", cacheMap);
    }

    /**
     * 数字公路-公路规划-当年计划、五年规划、中长期规划
     *
     * @return 结果
     */
    @RequestMapping("getHighWayPlanData")
    @ResponseBody
    @ApiOperation("数字公路-公路规划(当年计划、五年规划、中长期规划)")
    public Result<?> getHighWayPlanData() {
        // 当年规划-公路规划总投资(指标)
        List<Map<String, Object>> yearTotalData = dataScreenService.getTargetDataById("237");
        // 当年规划-饼图
        List<Map<String, Object>> yearChart  = dataScreenService.getTargetDataByIds("238", "239");
        List<Map<String, Object>> yearChart2 = dataScreenService.getTargetDataById("346");
        yearChart.addAll(yearChart2);

        // 五年规划-公路规划总投资(指标)
        List<Map<String, Object>> fiveTotalData = dataScreenService.getTargetDataById("242");
        // 五年规划-饼图
        List<Map<String, Object>> fiveChart = dataScreenService.getTargetDataByIds("243", "244");
        // 五年规划-规划指标
        List<Map<String, Object>> fiveData  = dataScreenService.getTargetDataByIds("240", "241");
        List<Map<String, Object>> fiveData2 = dataScreenService.getTargetDataByIds("245", "247");
        fiveData.addAll(fiveData2);

        // 中长期规划-规划建成总里程
        List<Map<String, String>> longTotalData = dataScreenService.getLongTermTotalData();
        // 中长期规划-饼图
        List<Map<String, Object>> longChart = dataScreenService.getTargetDataByIds("248", "250");
        // 中长期规划-规划指标
        List<Map<String, Object>> longData = dataScreenService.getTargetDataByIds("257", "258");

        Map<String, Object> map = MapUtil.newHashMap();
        map.put("yearTotalData", yearTotalData);
        map.put("yearChart", yearChart);
        map.put("fiveTotalData", fiveTotalData);
        map.put("fiveChart", fiveChart);
        map.put("fiveData", fiveData);
        map.put("longTotalData", longTotalData);
        map.put("longChart", longChart);
        map.put("longData", longData);

        return Result.OK(Boolean.TRUE, "查询成功！", map);
    }

    /**
     * 获取基础设施-建设板块的数据
     *
     * @param type 所属模块(1：公路；2：铁路；3：港航；4：民航；5：邮政)
     * @return 结果
     */
    @RequestMapping("getConstructionSectionData")
    @ResponseBody
    @ApiOperation("数字模块-获取基础设施-建设板块的数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type", value = "所属模块", allowableValues = "(1：公路；2：铁路；3：港航；4：民航；5：邮政)", required = true)
    })
    public Result<?> getConstructionSectionData(String type) {
        if ("1".equals(type)) {
            return this.getConstructionData("251", "252", "", "1");
        } else if ("2".equals(type)) {
            return this.getConstructionData("209", "210", "211", "1");
        } else if ("3".equals(type)) {
            return this.getConstructionData("282", "283", "284", "2");
        } else if ("4".equals(type)) {
            return this.getConstructionData("296", "297", "298", "2");
        } else if ("5".equals(type)) {
            return this.getConstructionData("231", "232", "233", "2");
        }
        return Result.OK(Boolean.FALSE, "查询失败，参数错误！", null);
    }

    /**
     * 数字铁路-十四五规划-拟开工项目(列表)
     *
     * @return 结果
     */
    @RequestMapping("getRailWayPlanProjectData")
    @ResponseBody
    @ApiOperation("数字铁路-十四五规划-拟开工项目(列表)")
    public Result<?> getRailWayPlanProjectData() {
        List<Map<String, String>> data = CacheUtils.get(DataScreenUtils.CACHE_NAME_SCREEN_LIST, "CACHE_KEY_RAIL_WAY_PLAN_PROJECT_DATA");
        if (data == null || data.isEmpty()) {
            data = dataScreenService.getRailWayPlanProjectData();
            CacheUtils.put(DataScreenUtils.CACHE_NAME_SCREEN_LIST, "CACHE_KEY_RAIL_WAY_PLAN_PROJECT_DATA", data);
        }
        return Result.OK(Boolean.TRUE, "查询成功！", data);
    }

    /**
     * 数字铁路-铁路外部安全环境(饼图和指标)
     *
     * @return 结果
     */
    @RequestMapping("getRailWaySecurityMetricData")
    @ResponseBody
    @ApiOperation("数字铁路-铁路外部安全环境(饼图和指标)")
    public Result<?> getRailWaySecurityMetricData() {
        // 年度累计排查(指标)
        List<Map<String, Object>> yearData = dataScreenService.getTargetDataById("212");
        // 年度累计排查(饼图)
        List<Map<String, Object>> yearChart  = dataScreenService.getTargetDataById("213");
        List<Map<String, Object>> yearChart2 = dataScreenService.getTargetDataById("345");
        yearChart.addAll(yearChart2);
        // 历史累计排查(指标)
        List<Map<String, Object>> historyData = dataScreenService.getTargetDataById("214");
        // 历史累计排查(饼图)
        List<Map<String, Object>> historyChart = dataScreenService.getTargetDataByIds("215", "216");
        Map<String, Object>       map          = MapUtil.newHashMap();
        map.put("yearData", yearData);
        map.put("yearChart", yearChart);
        map.put("historyData", historyData);
        map.put("historyChart", historyChart);
        return Result.OK(Boolean.TRUE, "查询成功！", map);
    }

    /**
     * 数字港航-航道养护-航道里程(柱形图和指标)
     *
     * @return 结果
     */
    @RequestMapping("getWaterWayMileageData")
    @ResponseBody
    @ApiOperation("数字港航-航道养护-航道里程(柱形图和指标)")
    public Result<?> getWaterWayMileageData() {
        Map<String, Object> dataMap = CacheUtils.get(DataScreenUtils.CACHE_NAME_SCREEN_LIST, "CACHE_KEY_WATER_WAY_MILEAGE_DATA");
        if (dataMap == null || dataMap.isEmpty()) {
            // 柱形图
            List<Map<String, String>> list = dataScreenService.getWaterWayMileageData();
            // 得到xAxis和data
            List<Object> xAxis = new ArrayList<>();
            List<Object> data  = new ArrayList<>();
            for (Map<String, String> map : list) {
                String name  = map.get("name");
                Object value = map.get("value");
                if (name != null) {
                    xAxis.add(name);
                }
                if (value != null) {
                    data.add(value);
                }
            }
            Map<String, Object> chartData = MapUtil.newHashMap();
            chartData.put("xAxis", xAxis);
            chartData.put("data", data);
            chartData.put("name", "里程");
            chartData.put("unit", "公里");
            // 指标
            List<Map<String, Object>> targetData = dataScreenService.getWaterWayTotalMileage();
            dataMap = MapUtil.newHashMap();
            dataMap.put("chartData", chartData);
            dataMap.put("targetData", targetData);
            CacheUtils.put(DataScreenUtils.CACHE_NAME_SCREEN_LIST, "CACHE_KEY_WATER_WAY_MILEAGE_DATA", dataMap);
        }
        return Result.OK(Boolean.TRUE, "查询成功！", dataMap);
    }

    /**
     * 得到XX建设板块的数据；包括当年计划投资(指标)/当年已完成投资(指标)、投资进度(饼图)、在建项目数(指标)
     *
     * @param amountId      完成投资金额/投资总额的数据ID
     * @param progressId    完成进度的数据ID
     * @param projectDataId 在建项目数的数据ID
     * @param type          类型（1：已知"已完成投资金额"的情况；2：已知"投资总额"的情况）
     * @return 结果
     */
    private Result<?> getConstructionData(String amountId, String progressId, String projectDataId, String type) {
        // 当年计划投资(指标)/当年已完成投资(指标)
        List<Map<String, Object>> data = dataScreenService.getTargetDataById(amountId);
        // 投资进度(饼图)
        List<Map<String, String>> chart = null;
        if ("1".equals(type)) {
            // 返回已完成投资、未完成投资、投资进度(已知"已完成投资金额"的情况)
            chart = dataScreenService.getProgressPieChartKnownFinishData(amountId, progressId);
        } else if ("2".equals(type)) {
            // 返回已完成投资、未完成投资、投资进度(已知"投资总额"的情况)
            chart = dataScreenService.getProgressPieChartKnownTotalData(amountId, progressId);
        }
        List<Map<String, Object>> projectData = null;
        if (StrUtil.isNotEmpty(projectDataId)) {
            // 在建项目数(指标)
            projectData = dataScreenService.getTargetDataById(projectDataId);
        }
        Map<String, Object> map = MapUtil.newHashMap();
        map.put("data", data);
        map.put("chart", chart);
        map.put("projectData", projectData);
        return Result.OK(Boolean.TRUE, "查询成功！", map);
    }

    /**
     * 运输服务-公共交通-每日客流量-动态指标(其它)
     *
     * @return 结果
     */
    @RequestMapping("getDailyPassengerFlowOtherData")
    @ResponseBody
    @ApiOperation("运输服务-公共交通-每日公交客流量-动态指标(其它)")
    public Result<?> getDailyPassengerFlowOtherData() {
        List<Map<String, String>> data = CacheUtils.get(DataScreenUtils.CACHE_NAME_SCREEN_LIST, "CACHE_KEY_DAILY_PASSENGER_FLOW_OTHER_DATA");
        if (data == null || data.isEmpty()) {
            data = dataScreenService.getDailyPassengerFlowOtherData();
            CacheUtils.put(DataScreenUtils.CACHE_NAME_SCREEN_LIST, "CACHE_KEY_DAILY_PASSENGER_FLOW_OTHER_DATA", data);
        }
        return Result.OK(Boolean.TRUE, "查询成功！", data);
    }

    /**
     * 运输服务-公共交通-公交排名(列表)
     *
     * @return 结果
     */
    @RequestMapping("getBusRankingData")
    @ResponseBody
    @ApiOperation("运输服务-公共交通-公交排名(列表)")
    public Result<?> getBusRankingData() {
        List<Map<String, String>> data = CacheUtils.get(DataScreenUtils.CACHE_NAME_SCREEN_LIST, "CACHE_KEY_BUS_RANKING_DATA");
        if (data == null || data.isEmpty()) {
            data = dataScreenService.getBusRankingData();
            CacheUtils.put(DataScreenUtils.CACHE_NAME_SCREEN_LIST, "CACHE_KEY_BUS_RANKING_DATA", data);
        }
        return Result.OK(Boolean.TRUE, "查询成功！", data);
    }

    /**
     * 运输服务-公共交通-轨道排名(列表)
     *
     * @return 结果
     */
    @RequestMapping("getRailRankingData")
    @ResponseBody
    @ApiOperation("运输服务-公共交通-轨道排名(列表)")
    public Result<?> getRailRankingData() {
        List<Map<String, String>> data = CacheUtils.get(DataScreenUtils.CACHE_NAME_SCREEN_LIST, "CACHE_KEY_RAIL_RANKING_DATA");
        if (data == null || data.isEmpty()) {
            data = dataScreenService.getRailRankingData();
            CacheUtils.put(DataScreenUtils.CACHE_NAME_SCREEN_LIST, "CACHE_KEY_RAIL_RANKING_DATA", data);
        }
        return Result.OK(Boolean.TRUE, "查询成功！", data);
    }

    /**
     * 运输服务-公共交通-出租车单日运营情况(指标)
     *
     * @return 结果
     */
    @RequestMapping("getTaxiOperationData")
    @ResponseBody
    @ApiOperation("运输服务-公共交通-出租车单日运营情况(指标)")
    public Result<?> getTaxiOperationData() {
        List<Map<String, String>> data = CacheUtils.get(DataScreenUtils.CACHE_NAME_SCREEN_LIST, "CACHE_KEY_TAXI_OPERATION_DATA");
        if (data == null || data.isEmpty()) {
            data = dataScreenService.getTaxiOperationData();
            CacheUtils.put(DataScreenUtils.CACHE_NAME_SCREEN_LIST, "CACHE_KEY_TAXI_OPERATION_DATA", data);
        }
        return Result.OK(Boolean.TRUE, "查询成功！", data);
    }

    /**
     * 运输服务-货运物流-危货道路运输信息(指标)
     *
     * @return 结果
     */
    @RequestMapping("getDangerousGoodsTransportData")
    @ResponseBody
    @ApiOperation("运输服务-货运物流-危货道路运输信息(指标)")
    public Result<?> getDangerousGoodsTransportData() {
        List<Map<String, Object>> basic = CacheUtils.get(DataScreenUtils.CACHE_NAME_SCREEN_LIST, "CACHE_KEY_DANGEROUS_GOODS_TRANSPORT_DATA");
        if (basic == null || basic.isEmpty()) {
            // 基础信息
            basic = dataScreenService.getTargetDataByIds("350", "351");
            // 订单数
            long                orders = dataScreenService.getDangerousGoodsWayBill("wnoti");
            Map<String, Object> map1   = MapUtil.newHashMap();
            map1.put("name", "订单数");
            map1.put("value", String.valueOf(orders));
            map1.put("unit", "单");
            // 货运量
            long                volume = dataScreenService.getDangerousGoodsWayBill("ftoti");
            Map<String, Object> map2   = MapUtil.newHashMap();
            map2.put("name", "货运量");
            map2.put("value", String.valueOf(volume));
            map2.put("unit", "吨");
            basic.add(map1);
            basic.add(map2);
            CacheUtils.put(DataScreenUtils.CACHE_NAME_SCREEN_LIST, "CACHE_KEY_DANGEROUS_GOODS_TRANSPORT_DATA", basic);
        }
        return Result.OK(Boolean.TRUE, "查询成功！", basic);
    }

    /**
     * 综合执法-行政处罚(指标和柱线图) 行政操作 行政拘留
     * 数据库字段名
     *
     * @return 结果
     */
    @RequestMapping("getPenaltyData")
    @ResponseBody
    @ApiOperation("综合执法-行政处罚(指标和柱线图)")
    public Result<?> getPenaltyData() {
        Map<String, Object> dataMap = CacheUtils.get(DataScreenUtils.CACHE_NAME_SCREEN_LIST, "CACHE_KEY_PENALTY_DATA");
        if (dataMap == null || dataMap.isEmpty()) {
            // 柱线图
            List<Object>        xAxis     = dataScreenService.getAdministrativeChartAxisData("month_casenum");
            List<Object>        data      = dataScreenService.getAdministrativeChartData("month_casenum");
            Map<String, Object> chartData = MapUtil.newHashMap();
            chartData.put("xAxis", xAxis);
            chartData.put("data", data);
            chartData.put("unit", "件");
            // 指标
            List<Map<String, String>> targetData = dataScreenService.getPenaltyTargetData();
            dataMap = MapUtil.newHashMap();
            dataMap.put("chartData", chartData);
            dataMap.put("targetData", targetData);
            CacheUtils.put(DataScreenUtils.CACHE_NAME_SCREEN_LIST, "CACHE_KEY_PENALTY_DATA", dataMap);
        }
        return Result.OK(Boolean.TRUE, "查询成功！", dataMap);
    }

    /**
     * 综合执法-行政强制(指标和柱线图)
     *
     * @return 结果
     */
    @RequestMapping("getCoercionData")
    @ResponseBody
    @ApiOperation("综合执法-行政强制(指标和柱线图)")
    public Result<?> getCoercionData() {
        Map<String, Object> dataMap = CacheUtils.get(DataScreenUtils.CACHE_NAME_SCREEN_LIST, "CACHE_KEY_COERCION_DATA");
        if (dataMap == null || dataMap.isEmpty()) {
            // 柱线图
            List<Object>        xAxis     = dataScreenService.getAdministrativeChartAxisData("month_forcenum");
            List<Object>        data      = dataScreenService.getAdministrativeChartData("month_forcenum");
            Map<String, Object> chartData = MapUtil.newHashMap();
            chartData.put("xAxis", xAxis);
            chartData.put("data", data);
            // 指标
            List<Map<String, String>> targetData = dataScreenService.getCoercionTargetData();
            dataMap = MapUtil.newHashMap();
            dataMap.put("chartData", chartData);
            dataMap.put("targetData", targetData);
            CacheUtils.put(DataScreenUtils.CACHE_NAME_SCREEN_LIST, "CACHE_KEY_COERCION_DATA", dataMap);
        }
        return Result.OK(Boolean.TRUE, "查询成功！", dataMap);
    }

    /**
     * 综合执法-行政检查(指标和饼图)
     *
     * @return 结果
     */
    @RequestMapping("getInspectionData")
    @ResponseBody
    @ApiOperation("综合执法-行政检查(指标和饼图)")
    public Result<?> getInspectionData() {
        Map<String, Object> dataMap = CacheUtils.get(DataScreenUtils.CACHE_NAME_SCREEN_LIST, "CACHE_KEY_INSPECTION_DATA");
        if (dataMap == null || dataMap.isEmpty()) {
            // 饼图-图例
            List<Object> xAxis = dataScreenService.getInspectionChartAxisData();
            // 饼图-数据
            List<Long>          data      = dataScreenService.getInspectionChartData();
            Map<String, Object> chartData = MapUtil.newHashMap();
            chartData.put("name", xAxis);
            chartData.put("data", data);
            chartData.put("unit", "次");
            // 指标
            List<Map<String, String>> targetData = dataScreenService.getInspectionTargetData();
            dataMap = MapUtil.newHashMap();
            dataMap.put("chartData", chartData);
            dataMap.put("targetData", targetData);
            CacheUtils.put(DataScreenUtils.CACHE_NAME_SCREEN_LIST, "CACHE_KEY_INSPECTION_DATA", dataMap);
        }
        return Result.OK(Boolean.TRUE, "查询成功！", dataMap);
    }

    /**
     * 综合执法-投诉处理(指标和柱形图)
     *
     * @return 结果
     */
    @RequestMapping("getComplaintsData")
    @ResponseBody
    @ApiOperation("综合执法-投诉处理(指标和柱形图)")
    public Result<?> getComplaintData() {
        Map<String, Object> dataMap = CacheUtils.get(DataScreenUtils.CACHE_NAME_SCREEN_LIST, "CACHE_KEY_COMPLAINT_DATA");
        if (dataMap == null || dataMap.isEmpty()) {
            // X轴
            List<Object> xAxis = dataScreenService.getAdministrativeChartAxisData("month_plaintnum");
            // 投诉量
            List<Object> tsData = dataScreenService.getAdministrativeChartData("month_plaintnum");
            // 办结量
            List<Object>        bjData    = dataScreenService.getAdministrativeChartData("month_handlenum");
            Map<String, Object> chartData = MapUtil.newHashMap();
            chartData.put("xAxis", xAxis);
            chartData.put("tsData", tsData);
            chartData.put("bjData", bjData);
            // 指标
            List<Map<String, String>> targetData = dataScreenService.getComplaintTargetData();
            dataMap = MapUtil.newHashMap();
            dataMap.put("chartData", chartData);
            dataMap.put("targetData", targetData);
            CacheUtils.put(DataScreenUtils.CACHE_NAME_SCREEN_LIST, "CACHE_KEY_COMPLAINT_DATA", dataMap);
        }
        return Result.OK(Boolean.TRUE, "查询成功！", dataMap);
    }

    /**
     * 综合执法-公路治超(指标)
     *
     * @return 结果
     */
    @RequestMapping("getControlOverData")
    @ResponseBody
    @ApiOperation("综合执法-公路治超(指标)")
    public Result<?> getControlOverData() {
        List<Map<String, String>> data = CacheUtils.get(DataScreenUtils.CACHE_NAME_SCREEN_LIST, "CACHE_KEY_CONTROL_OVER_DATA");
        if (data == null || data.isEmpty()) {
            // 指标
            data = dataScreenService.getControlOverData();
            CacheUtils.put(DataScreenUtils.CACHE_NAME_SCREEN_LIST, "CACHE_KEY_CONTROL_OVER_DATA", data);
        }
        return Result.OK(Boolean.TRUE, "查询成功！", data);
    }

    /**
     * 审批信用-审批-全市办件总量(饼图(等级和类型)和指标)
     *
     * @return 结果
     */
    @RequestMapping("getCityPaperWorkTotalData")
    @ResponseBody
    @ApiOperation("审批信用-审批-全市办件总量(饼图(等级和类型)和指标)")
    public Result<?> getCityPaperWorkTotalData() {
        Map<String, List<Map<String, Object>>> data = CacheUtils.get(DataScreenUtils.CACHE_NAME_SCREEN_LIST, "CACHE_KEY_CITY_PAPER_WORK_TOTAL_DATA");
        if (data == null || data.isEmpty()) {
            // 办件总量(指标)
            List<Map<String, Object>> totalData = new ArrayList<>();
            totalData.add(dataScreenService.getApprovalEventCountMapData("办件总量", "sum(bjzl)"));
            // 饼图(等级)
            List<Map<String, Object>> levelChart = new ArrayList<>();
            levelChart.add(dataScreenService.getApprovalEventCountMapData("重大件办理量", "sum(zdjbll)"));
            levelChart.add(dataScreenService.getApprovalEventCountMapData("一般件办理量", "sum(ybjbll)"));
            levelChart.add(dataScreenService.getApprovalEventCountMapData("即办件办理量", "sum(jbjbll)"));
            // 饼图(类型)
            List<Map<String, Object>> typeChart = new ArrayList<>();
            typeChart.add(dataScreenService.getApprovalEventCountMapData("道路运输办件量", "sum(dlysbjl)"));
            typeChart.add(dataScreenService.getApprovalEventCountMapData("港航海事办件量", "sum(ghhsbjl)"));
            typeChart.add(dataScreenService.getApprovalEventCountMapData("超限运输办件量", "sum(cxysbjl)"));
            typeChart.add(dataScreenService.getApprovalEventCountMapData("工程建设办件量", "sum(gcjsbjl)"));
            data = MapUtil.newHashMap();
            data.put("totalData", totalData);
            data.put("levelChart", levelChart);
            data.put("typeChart", typeChart);
            CacheUtils.put(DataScreenUtils.CACHE_NAME_SCREEN_LIST, "CACHE_KEY_CITY_PAPER_WORK_TOTAL_DATA", data);
        }
        return Result.OK(Boolean.TRUE, "查询成功！", data);
    }

    /**
     * 审批信用-审批-高频事件办件Top10(列表)
     *
     * @return 结果
     */
    @RequestMapping("getHighFrequencyPaperWorkTopData")
    @ResponseBody
    @ApiOperation("审批信用-审批-高频事件办件Top10(列表)")
    public Result<?> getHighFrequencyPaperWorkTopData() {
        List<Map<String, String>> data = CacheUtils.get(DataScreenUtils.CACHE_NAME_SCREEN_LIST, "CACHE_KEY_HIGH_FREQUENCY_PAPER_WORK_TOP_DATA");
        if (data == null || data.isEmpty()) {
            data = dataScreenService.getHighFrequencyPaperWorkTopData();
            CacheUtils.put(DataScreenUtils.CACHE_NAME_SCREEN_LIST, "CACHE_KEY_HIGH_FREQUENCY_PAPER_WORK_TOP_DATA", data);
        }
        return Result.OK(Boolean.TRUE, "查询成功！", data);
    }

    /**
     * 审批信用-审批-政府服务工作(横向柱形图)
     *
     * @return 结果
     */
    @RequestMapping("getGovernmentWorkData")
    @ResponseBody
    @ApiOperation("审批信用-审批-政府服务工作(横向柱形图)")
    public Result<?> getGovernmentWorkData() {
        Map<String, Object> chartData = CacheUtils.get(DataScreenUtils.CACHE_NAME_SCREEN_LIST, "CACHE_KEY_GOVERNMENT_WORK_DATA");
        if (chartData == null || chartData.isEmpty()) {
            List<Object> yAxis = new ArrayList<>();
            List<Object> data  = new ArrayList<>();
            // 秒批秒办
            yAxis.add("秒批秒办");
            data.add(dataScreenService.getApprovalEventCountData("sum(mpmb)"));
            // 全程网办
            yAxis.add("全程网办");
            data.add(dataScreenService.getApprovalEventCountData("sum(qcwb)"));
            // 川渝通办
            yAxis.add("川渝通办");
            data.add(dataScreenService.getApprovalEventCountData("sum(cytb)"));
            chartData = MapUtil.newHashMap();
            chartData.put("yAxis", yAxis);
            chartData.put("data", data);
            CacheUtils.put(DataScreenUtils.CACHE_NAME_SCREEN_LIST, "CACHE_KEY_GOVERNMENT_WORK_DATA", chartData);
        }
        return Result.OK(Boolean.TRUE, "查询成功！", chartData);
    }

    /**
     * 审批信用-信用-从业企业、人员参评规模(饼图)
     *
     * @return 结果
     */
    @RequestMapping("getPracticeEnterpriseQuantityData")
    @ResponseBody
    @ApiOperation("审批信用-信用-从业企业、人员参评规模(饼图)")
    public Result<?> getPracticeEnterpriseQuantityData() {
        Map<String, Object> dataMap = CacheUtils.get(DataScreenUtils.CACHE_NAME_SCREEN_LIST, "CACHE_KEY_PRACTICE_ENTERPRISE_QUANTITY_DATA");

        if (dataMap == null || dataMap.isEmpty()) {

            dataMap = MapUtil.newHashMap();
            List<Map<String, Object>> targetData = new ArrayList<>();
            // 从业企业总量
            Map<String, Object> m1 = MapUtil.newHashMap();
            m1.put("name", "从业企业总量");
            m1.put("unit", "家");
            m1.put("data", dataScreenService.getEnterprisePersonnelCountData("IFNULL(sum(num),0)", "%企业%"));
            targetData.add(m1);
            // 从业企业人员
            Map<String, Object> m2 = MapUtil.newHashMap();
            m2.put("name", "从业企业人员");
            m2.put("unit", "人");
            m2.put("data", dataScreenService.getEnterprisePersonnelCountData("IFNULL(sum(num),0)", "%人员%"));
            targetData.add(m2);
            dataMap.put("targetData", targetData);

            List<Map<String, Object>> chartData = new ArrayList<>();
            // 公路建设
            Map<String, Object> m3 = MapUtil.newHashMap();
            m3.put("name", "公路建设");
            m3.put("unit", "家");
            m3.put("data", dataScreenService.getEnterprisePersonnelCountData("IFNULL(sum(num),0)", "%公路工程建设领域企业基本%"));
            chartData.add(m3);
            // 道路运输
            Map<String, Object> m4 = MapUtil.newHashMap();
            m4.put("name", "道路运输");
            m4.put("unit", "家");
            m4.put("data", dataScreenService.getEnterprisePersonnelCountData("IFNULL(sum(num),0)", "%道路企业基本%"));
            chartData.add(m4);
            // 水运建设
            Map<String, Object> m5 = MapUtil.newHashMap();
            m5.put("name", "水运建设");
            m5.put("unit", "家");
            m5.put("data", dataScreenService.getEnterprisePersonnelCountData("IFNULL(sum(num),0)", "%水运工程建设领域企业基本%"));
            chartData.add(m5);
            // 水路运输
            Map<String, Object> m6 = MapUtil.newHashMap();
            m6.put("name", "水路运输");
            m6.put("unit", "家");
            m6.put("data", dataScreenService.getEnterprisePersonnelCountData("IFNULL(sum(num),0)", "%水运运输企业基本%"));
            chartData.add(m6);

            dataMap.put("chartData", chartData);

            CacheUtils.put(DataScreenUtils.CACHE_NAME_SCREEN_LIST, "CACHE_KEY_PRACTICE_ENTERPRISE_QUANTITY_DATA", dataMap);
        }
        return Result.OK(Boolean.TRUE, "查询成功！", dataMap);
    }

    /**
     * 审批信用-信用-动态评价和安全一票否决(列表)
     *
     * @return 结果
     */
    @RequestMapping("getDynamicEvaluationData")
    @ResponseBody
    @ApiOperation("审批信用-信用-动态评价和安全一票否决(列表)")
    public Result<?> getDynamicEvaluationData() {
        List<Map<String, String>> data = CacheUtils.get(DataScreenUtils.CACHE_NAME_SCREEN_LIST, "CACHE_KEY_DYNAMIC_EVALUATION_DATA");
        if (data == null || data.isEmpty()) {
            data = dataScreenService.getDynamicEvaluationData();
            CacheUtils.put(DataScreenUtils.CACHE_NAME_SCREEN_LIST, "CACHE_KEY_DYNAMIC_EVALUATION_DATA", data);
        }
        return Result.OK(Boolean.TRUE, "查询成功！", data);
    }

    /**
     * 审批信用-信用-经典案例(列表)
     *
     * @return 结果
     */
    @RequestMapping("getClassicCaseData")
    @ResponseBody
    @ApiOperation("审批信用-信用-经典案例(列表)")
    public Result<?> getClassicCaseData() {
        List<Map<String, String>> data = CacheUtils.get(DataScreenUtils.CACHE_NAME_SCREEN_LIST, "CACHE_KEY_CLASSIC_CASE_DATA");
        if (data == null || data.isEmpty()) {
            data = dataScreenService.getClassicCaseData();
            CacheUtils.put(DataScreenUtils.CACHE_NAME_SCREEN_LIST, "CACHE_KEY_CLASSIC_CASE_DATA", data);
        }
        return Result.OK(Boolean.TRUE, "查询成功！", data);
    }

    /**
     * 审批信用-信用-道路运输重点监管名单(列表)
     *
     * @return 结果
     */
    @RequestMapping("getFocusRegulationData")
    @ResponseBody
    @ApiOperation("审批信用-信用-道路运输重点监管名单(列表)")
    public Result<?> getFocusRegulationData() {
        List<Map<String, String>> data = CacheUtils.get(DataScreenUtils.CACHE_NAME_SCREEN_LIST, "CACHE_KEY_FOCUS_REGULATION_DATA");
        if (data == null || data.isEmpty()) {
            data = dataScreenService.getFocusRegulationData();
            CacheUtils.put(DataScreenUtils.CACHE_NAME_SCREEN_LIST, "CACHE_KEY_FOCUS_REGULATION_DATA", data);
        }
        return Result.OK(Boolean.TRUE, "查询成功！", data);
    }

    /**
     * 审批信用-信用-信用数据采集归集前五名(列表)
     *
     * @return 结果
     */
    @RequestMapping("getCreditGatherTopData")
    @ResponseBody
    @ApiOperation("审批信用-信用-信用数据采集归集前五名(列表)")
    public Result<?> getCreditGatherTopData() {
        List<Map<String, String>> data = CacheUtils.get(DataScreenUtils.CACHE_NAME_SCREEN_LIST, "CACHE_KEY_CREDIT_GATHER_TOP_DATA");
        if (data == null || data.isEmpty()) {
            data = dataScreenService.getCreditGatherTopData();
            CacheUtils.put(DataScreenUtils.CACHE_NAME_SCREEN_LIST, "CACHE_KEY_CREDIT_GATHER_TOP_DATA", data);
        }
        return Result.OK(Boolean.TRUE, "查询成功！", data);
    }

    /**
     * 审批信用-信用-信用指标分领域统计(横向柱形图)
     *
     * @return 结果
     */
    @RequestMapping("getCreditTargetByFieldData")
    @ResponseBody
    @ApiOperation("审批信用-信用-信用指标分领域统计(横向柱形图)")
    public Result<?> getCreditTargetByFieldData() {
        Map<String, Object> chartData = CacheUtils.get(DataScreenUtils.CACHE_NAME_SCREEN_LIST, "CACHE_KEY_CREDIT_TARGET_BY_FIELD_DATA");
        if (chartData == null || chartData.isEmpty()) {
            // Y轴
            List<Object> yAxis = new ArrayList<>();
            // 信用指标
            List<Object>              data = new ArrayList<>();
            List<Map<String, Object>> list = dataScreenService.getCreditTargetByFieldData();
            for (Map<String, Object> map : list) {
                Object name  = map.get("name");
                Object value = map.get("value");
                if (name != null) {
                    yAxis.add(name);
                }
                if (value != null) {
                    data.add(value);
                }
            }


            chartData = MapUtil.newHashMap();
            chartData.put("yAxis", yAxis);
            chartData.put("data", data);
            chartData.put("unit", "条");
            chartData.put("name", "采集量");
            CacheUtils.put(DataScreenUtils.CACHE_NAME_SCREEN_LIST, "CACHE_KEY_CREDIT_TARGET_BY_FIELD_DATA", chartData);
        }
        return Result.OK(Boolean.TRUE, "查询成功！", chartData);
    }

    /**
     * 审批信用-信用-全市信用评价信息采集量(曲线图)
     *
     * @return 结果
     */
    @RequestMapping("getCityCreditEvaluationData")
    @ResponseBody
    @ApiOperation("审批信用-信用-全市信用评价信息采集量(曲线图)")
    public Result<?> getCityCreditEvaluationData() {
        Map<String, Object> chartData = CacheUtils.get(DataScreenUtils.CACHE_NAME_SCREEN_LIST, "CACHE_KEY_CITY_CREDIT_EVALUATION_DATA");
        if (chartData == null || chartData.isEmpty()) {
            chartData = MapUtil.newHashMap();
            // X轴
            List<Object> xAxis = new ArrayList<>();
            // 今年事故数
            List<Object>              data = new ArrayList<>();
            List<Map<String, Object>> list = dataScreenService.getCityCreditEvaluationData();
            for (Map<String, Object> map : list) {
                Object name  = map.get("name");
                Object value = map.get("value");
                if (name != null) {
                    xAxis.add(name);
                }
                if (value != null) {
                    data.add(value);
                }
            }
            chartData.put("xAxis", xAxis);
            chartData.put("data", data);
            chartData.put("unit", "条");
            chartData.put("name", "采集量");
            CacheUtils.put(DataScreenUtils.CACHE_NAME_SCREEN_LIST, "CACHE_KEY_CITY_CREDIT_EVALUATION_DATA", chartData);
        }
        return Result.OK(Boolean.TRUE, "查询成功！", chartData);
    }

    /**
     * 审批信用-信用-从业企业、人员信用评价(列表)
     *
     * @return 结果
     */
    @RequestMapping("getEpCreditRatingData")
    @ResponseBody
    @ApiOperation("审批信用-信用-从业企业、人员信用评价(列表)")
    public Result<?> getEpCreditRatingData() {
        List<Map<String, String>> data = CacheUtils.get(DataScreenUtils.CACHE_NAME_SCREEN_LIST, "CACHE_KEY_EP_CREDIT_RATING_DATA");
        if (data == null || data.isEmpty()) {
            data = dataScreenService.getEpCreditRatingData();
            CacheUtils.put(DataScreenUtils.CACHE_NAME_SCREEN_LIST, "CACHE_KEY_EP_CREDIT_RATING_DATA", data);
        }
        return Result.OK(Boolean.TRUE, "查询成功！", data);
    }

    /**
     * 安全应急-渝运安-风险隐患趋势(折线图和指标) 列名
     *
     * @return 结果
     */
    @RequestMapping("getRiskHazardTrendData")
    @ResponseBody
    @ApiOperation("安全应急-渝运安-风险隐患趋势(折线图和指标)")
    public Result<?> getRiskPitfallTrendData() {
        Map<String, Object> map = CacheUtils.get(DataScreenUtils.CACHE_NAME_SCREEN_LIST, "CACHE_KEY_RISK_PITFALL_TREND_DATA");
        if (map == null || map.isEmpty()) {
            // 风险隐患趋势(折线图)
            // X轴
            List<Object> xAxis = dataScreenService.getRiskHazardTrendData("countmonth");
            // 隐患数量
            List<Object> hidden = dataScreenService.getRiskHazardTrendData("itotal");
            // 解除数量
            List<Object>        eliminate = dataScreenService.getRiskHazardTrendData("ritotal");
            Map<String, Object> chart     = MapUtil.newHashMap();
            chart.put("xAxis", xAxis);
            chart.put("hidden", hidden);
            chart.put("eliminate", eliminate);
            // 隐患解除率(指标)
            List<Map<String, String>> data = dataScreenService.getRiskHazardRemovalRate();
            map = MapUtil.newHashMap();
            map.put("chart", chart);
            map.put("data", data);
            CacheUtils.put(DataScreenUtils.CACHE_NAME_SCREEN_LIST, "CACHE_KEY_RISK_PITFALL_TREND_DATA", map);
        }
        return Result.OK(Boolean.TRUE, "查询成功！", map);
    }

    /**
     * 安全应急-渝运安-两客一危(指标)
     *
     * @return 结果
     */
    @RequestMapping("getCbvData")
    @ResponseBody
    @ApiOperation("安全应急-渝运安-两客一危(指标)")
    public Result<?> getCbvData() {
        List<Map<String, String>> data = CacheUtils.get(DataScreenUtils.CACHE_NAME_SCREEN_LIST, "CACHE_KEY_CBV_DATA");
        if (data == null || data.isEmpty()) {
            data = dataScreenService.getCbvData();
            CacheUtils.put(DataScreenUtils.CACHE_NAME_SCREEN_LIST, "CACHE_KEY_CBV_DATA", data);
        }
        return Result.OK(Boolean.TRUE, "查询成功！", data);
    }

    /**
     * 安全应急-渝运安-区县百车隐患数前Top10(列表)
     *
     * @return 结果
     */
    @RequestMapping("getHundredCartPitfallTopData")
    @ResponseBody
    @ApiOperation("安全应急-渝运安-区县百车隐患数前Top10(列表)")
    public Result<?> getHundredCartPitfallTopData() {
        List<Map<String, String>> data = CacheUtils.get(DataScreenUtils.CACHE_NAME_SCREEN_LIST, "CACHE_KEY_HUNDRED_CART_PITFALL_TOP_DATA");
        if (data == null || data.isEmpty()) {
            data = dataScreenService.getHundredCartPitfallTopData();
            CacheUtils.put(DataScreenUtils.CACHE_NAME_SCREEN_LIST, "CACHE_KEY_HUNDRED_CART_PITFALL_TOP_DATA", data);
        }
        return Result.OK(Boolean.TRUE, "查询成功！", data);
    }

    /**
     * 安全应急-渝运安-车辆动态监督考核(前3和后3)
     *
     * @return 结果
     */
    @RequestMapping("getCarAssessData")
    @ResponseBody
    @ApiOperation("安全应急-渝运安-车辆动态监督考核前3和后3")
    public Result<?> getCarAssessData() {
        Map<String, Object> map = CacheUtils.get(DataScreenUtils.CACHE_NAME_SCREEN_LIST, "CACHE_KEY_CAR_ASSESS_DATA");
        if (map == null || map.isEmpty()) {
            // 前三
            List<Map<String, String>> topData = dataScreenService.getCarAssessData("rank asc");
            // 后三
            List<Map<String, String>> lastData = dataScreenService.getCarAssessData("rank desc");
            map = MapUtil.newHashMap();
            map.put("topData", topData);
            map.put("lastData", lastData);
            CacheUtils.put(DataScreenUtils.CACHE_NAME_SCREEN_LIST, "CACHE_KEY_CAR_ASSESS_DATA", map);
        }
        return Result.OK(Boolean.TRUE, "查询成功！", map);
    }

    /**
     * 安全应急-交通应急资源-水上救援分布(列表)
     *
     * @return 结果
     */
    @RequestMapping("getWaterRescueData")
    @ResponseBody
    @ApiOperation("安全应急-交通应急资源-水上救援分布(列表)")
    public Result<?> getWaterRescueData() {
        List<Map<String, String>> data = CacheUtils.get(DataScreenUtils.CACHE_NAME_SCREEN_LIST, "CACHE_KEY_WATER_RESCUE_DATA");
        if (data == null || data.isEmpty()) {
            data = dataScreenService.getWaterRescueData();
            CacheUtils.put(DataScreenUtils.CACHE_NAME_SCREEN_LIST, "CACHE_KEY_WATER_RESCUE_DATA", data);
        }
        return Result.OK(Boolean.TRUE, "查询成功！", data);
    }

    /**
     * 安全应急-交通应急资源-公路阻断信息(列表)
     *
     * @return 结果
     */
    @RequestMapping("getHighWayBlockageData")
    @ResponseBody
    @ApiOperation("安全应急-交通应急资源-公路阻断信息(列表)")
    public Result<?> getHighWayBlockageData() {
        List<Map<String, String>> data = CacheUtils.get(DataScreenUtils.CACHE_NAME_SCREEN_LIST, "CACHE_KEY_HIGH_WAY_BLOCKAGE_DATA");
        if (data == null || data.isEmpty()) {
            data = dataScreenService.getHighWayBlockageData();
            CacheUtils.put(DataScreenUtils.CACHE_NAME_SCREEN_LIST, "CACHE_KEY_HIGH_WAY_BLOCKAGE_DATA", data);
        }
        return Result.OK(Boolean.TRUE, "查询成功！", data);
    }

    /**
     * 安全应急-平安交通指数-获取最新的有数据的月份
     *
     * @return 结果
     */
    @RequestMapping("getMonthData")
    @ResponseBody
    @ApiOperation("安全应急-平安交通指数-获取最新的有数据的月份")
    public Result<?> getMonthData() {
        Map<String, Object> map = MapUtil.newHashMap();
        map.put("month", dataScreenService.getMonthData());
        return Result.OK(Boolean.TRUE, "查询成功！", map);
    }

    /**
     * 安全应急-平安交通指数-月度事故信息(饼图和指标)
     *
     * @param month 查询条件 月份(默认上一月)
     * @return 结果
     */
    @RequestMapping("getMonthlyAccidentData")
    @ResponseBody
    @ApiOperation("安全应急-平安交通指数-月度事故信息(饼图和指标)")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "month", value = "月份", defaultValue = "1", dataType = "数字")
    })
    public Result<?> getMonthlyAccidentData(String month) {
        if (StrUtil.isEmpty(month)) {
            // 获取最新的有数据的月份
            month = dataScreenService.getMonthData();
        }
        // 饼图
        List<Map<String, String>> chartData = dataScreenService.getMonthlyAccidentByTypeData(month);
        // 指标
        List<Map<String, String>>              targetData = dataScreenService.getMonthlyAccidentData(month);
        Map<String, List<Map<String, String>>> map        = MapUtil.newHashMap();
        map.put("chartData", chartData);
        map.put("targetData", targetData);
        return Result.OK(Boolean.TRUE, "查询成功！", map);
    }

    /**
     * 安全应急-平安交通指数-月度事故同比情况(柱形图)
     *
     * @param month 查询条件 月份(默认上一月)
     * @return 结果
     */
    @RequestMapping("getMonthlyAccidentYoyData")
    @ResponseBody
    @ApiOperation("安全应急-平安交通指数-月度事故同比情况(柱形图)")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "month", value = "月份", defaultValue = "1", dataType = "数字")
    })
    public Result<?> getMonthlyAccidentYoyData(String month) {
        if (StrUtil.isEmpty(month)) {
            // 获取最新的有数据的月份
            month = dataScreenService.getMonthData();
        }
        // 横向柱形图
        // Y轴
        List<Object> yAxis = new ArrayList<>();
        String year = String.valueOf(DateUtil.thisYear());
        // 当年某月数据
        List<Map<String, String>> yearData = dataScreenService.getMonthlyAccidentYoyData(year, month);
        // 去年同期数据
        List<Map<String, String>> lastYearData = dataScreenService.getMonthlyAccidentYoyData(String.valueOf(Integer.parseInt(year) - 1), month);
        Map<String, Object>       dataMap      = MapUtil.newHashMap();
        // 今年事故数
        List<Object> sgslList1 = new ArrayList<>();
        for (Map<String, String> map : yearData) {
            String sglx = map.get("sglx");
            Object sgsl = map.get("sgsl");
            if (sglx != null) {
                yAxis.add(sglx);
            }
            if (sgsl != null) {
                sgslList1.add(sgsl);
            }
        }
        // 去年事故数
        List<Object> sgslList2 = new ArrayList<>();
        for (Map<String, String> map : lastYearData) {
            Object sgsl = map.get("sgsl");
            String sglx = map.get("sglx");
            if (sgsl != null) {
                sgslList2.add(sgsl);
            }
            if (sglx != null) {
                yAxis.add(sglx);
            }
        }
        dataMap.put("xAxis", yAxis);
        dataMap.put("今年", sgslList1);
        dataMap.put("去年", sgslList2);
        return Result.OK(Boolean.TRUE, "查询成功！", dataMap);
    }

    /**
     * 安全应急-平安交通指数-地区事故数(列表)
     *
     * @return 结果
     */
    @RequestMapping("getAreaAccidentData")
    @ResponseBody
    @ApiOperation("安全应急-平安交通指数-地区事故数据(列表)")
    public Result<?> getAreaAccidentData() {
        Map<String, List<Map<String, String>>> map = CacheUtils.get(DataScreenUtils.CACHE_NAME_SCREEN_LIST, "CACHE_KEY_AREA_ACCIDENT_DATA");
        if (map == null || map.isEmpty()) {
            // 中心城区事故
            List<Map<String, String>> centerAreaData = dataScreenService.getCenterAreaAccidentData("中心城区");
            // 远郊区县事故
            List<Map<String, String>> suburbanAreasData = dataScreenService.getCenterAreaAccidentData("远郊区县");
            // 将两个数据放入一个map中
            map = MapUtil.newHashMap();
            map.put("centerAreaData", centerAreaData);
            map.put("suburbanAreasData", suburbanAreasData);
            CacheUtils.put(DataScreenUtils.CACHE_NAME_SCREEN_LIST, "CACHE_KEY_AREA_ACCIDENT_DATA", map);
        }
        return Result.OK(Boolean.TRUE, "查询成功！", map);
    }

    /**
     * 安全应急-平安交通指数-年度事故数/死亡人数对比(柱状图)
     *
     * @return 结果
     */
    @RequestMapping("getYearAccidentAndDeathData")
    @ResponseBody
    @ApiOperation("安全应急-平安交通指数-年度事故数/死亡人数对比(柱状图)")
    public Result<?> getYearAccidentAndDeathData() {
        Map<Object, Object> map = CacheUtils.get(DataScreenUtils.CACHE_NAME_SCREEN_LIST, "CACHE_KEY_YEAR_ACCIDENT_AND_DEATH_DATA");
        if (map == null || map.isEmpty()) {
            Map<String, Object> dataMap1 = this.getAnnualSummaryData("sg");
            Map<String, Object> dataMap2 = this.getAnnualSummaryData("sw");
            map = MapUtil.newHashMap();
            map.put("accidentData", dataMap1);
            map.put("deathData", dataMap2);
            CacheUtils.put(DataScreenUtils.CACHE_NAME_SCREEN_LIST, "CACHE_KEY_YEAR_ACCIDENT_AND_DEATH_DATA", map);
        }
        return Result.OK(Boolean.TRUE, "查询成功！", map);
    }

    /**
     * 获取严重类型分类的年度事故/死亡数数据
     *
     * @return 结果
     */
    private Map<String, Object> getAnnualSummaryData(String type) {
        String year = String.valueOf(DateUtil.thisYear());
        // 今年死亡人数数据
        List<Map<String, String>> yearData = dataScreenService.getYearAccidentDeathData(year);
        // 去年死亡人数数据
        List<Map<String, String>> lastYearData = dataScreenService.getYearAccidentDeathData(String.valueOf(Integer.parseInt(year) - 1));
        // 结果
        Map<String, Object> dataMap = MapUtil.newHashMap();
        // 今年事故数
        List<Object> sgslList1 = new ArrayList<>();
        // 今年死亡人数
        List<Object> swrsList1 = new ArrayList<>();
        // 严重类型
        List<Object> xAxis = new ArrayList<>();
        for (Map<String, String> map : yearData) {
            String sglx = map.get("sglx");
            Object sgsl = map.get("sgsl");
            Object swrs = map.get("swrs");
            if (sglx != null) {
                xAxis.add(sglx);
            }
            if (sgsl != null) {
                sgslList1.add(sgsl);
            }
            if (swrs != null) {
                swrsList1.add(swrs);
            }
        }
        // 去年事故数
        List<Object> sgslList2 = new ArrayList<>();
        // 去年死亡人数
        List<Object> swrsList2 = new ArrayList<>();

        // 去年事故数
        List<Object> sgslList3 = new ArrayList<>();
        // 去年死亡人数
        List<Object> swrsList3 = new ArrayList<>();

        for (Map<String, String> map : lastYearData) {
            String sglx = map.get("sglx");
            Object sgsl = map.get("sgsl");
            Object swrs = map.get("swrs");
            if (sglx != null) {
                xAxis.add(sglx);
            }
            if (sgsl != null) {
                sgslList2.add(sgsl);
                sgslList3.add(0);
            }
            if (swrs != null) {
                swrsList2.add(swrs);
                swrsList3.add(0);
            }
        }
        dataMap.put("xAxis", xAxis);
        if (sgslList1.isEmpty()) {
            sgslList1.addAll(sgslList3);
        }
        if (swrsList1.isEmpty()) {
            swrsList1.addAll(swrsList3);
        }
        dataMap.put("今年", type.equals("sg") ? sgslList1 : swrsList1);
        dataMap.put("去年", type.equals("sg") ? sgslList2 : swrsList2);
        return dataMap;
    }

    /**
     * 安全应急-平安交通指数-年度事故趋势(柱状图)
     *
     * @return 结果
     */
    @RequestMapping("getYearAccidentTrendData")
    @ResponseBody
    @ApiOperation("安全应急-平安交通指数-年度事故趋势(柱状图)")
    public Result<?> getYearAccidentTrendData() {
        Map<Object, Object> map = CacheUtils.get(DataScreenUtils.CACHE_NAME_SCREEN_LIST, "CACHE_KEY_YEAR_ACCIDENT_TREND_DATA");
        if (map == null || map.isEmpty()) {
            // 事故数
            Map<String, Object> dataMap1 = this.getYearAccidentTrendDataByType("sg");
            // 死亡人数
            Map<String, Object> dataMap2 = this.getYearAccidentTrendDataByType("sw");
            map = MapUtil.newHashMap();
            map.put("accidentData", dataMap1);
            map.put("deathData", dataMap2);
            CacheUtils.put(DataScreenUtils.CACHE_NAME_SCREEN_LIST, "CACHE_KEY_YEAR_ACCIDENT_TREND_DATA", map);
        }
        return Result.OK(Boolean.TRUE, "查询成功！", map);
    }

    /**
     * 获取按照严重程度分类的年度事故数/死亡人数数据
     *
     * @return 结果
     */
    private Map<String, Object> getYearAccidentTrendDataByType(String type) {
        String year = String.valueOf(DateUtil.thisYear());
        // 今年事故数/死亡人数
        List<Map<String, String>> x1 = dataScreenService.getYearAccidentDeathNumberData(year);
        // 去年事故数/死亡人数
        List<Map<String, String>> x2      = dataScreenService.getYearAccidentDeathNumberData(String.valueOf(Integer.parseInt(year) - 1));
        Map<String, Object>       dataMap = MapUtil.newHashMap();
        // 今年事故数
        List<Object> sglxList  = new ArrayList<>();
        List<Object> sgslList1 = new ArrayList<>();
        List<Object> swrsList1 = new ArrayList<>();
        for (Map<String, String> map : x1) {
            String sglx = map.get("sglx");
            Object sgsl = map.get("sgsl");
            Object swrs = map.get("swrs");
            if (sglx != null) {
                sglxList.add(sglx);
            }
            if (sgsl != null) {
                sgslList1.add(sgsl);
            }
            if (swrs != null) {
                swrsList1.add(swrs);
            }
        }
        // 去年事故数
        List<Object> sgslList2 = new ArrayList<>();
        List<Object> swrsList2 = new ArrayList<>();
        // 如果今年的数据为空，则赋值为0
        List<Object> sgslList3 = new ArrayList<>();
        List<Object> swrsList3 = new ArrayList<>();
        for (Map<String, String> map : x2) {
            String sglx = map.get("sglx");
            Object sgsl = map.get("sgsl");
            Object swrs = map.get("swrs");
            if (sgsl != null) {
                sgslList2.add(sgsl);
                sgslList3.add(0);
            }
            if (swrs != null) {
                swrsList2.add(swrs);
                swrsList3.add(0);
            }
            if (sglx != null) {
                sglxList.add(sglx);
            }

        }
        Set<Object> set = new HashSet<>(sglxList);
        sglxList.clear();
        sglxList.addAll(set);
        dataMap.put("xAxis", sglxList);
        if (sgslList1.isEmpty() || sgslList1.size() == 1) {
            sgslList1.clear();
            sgslList1.addAll(sgslList3);
        }
        if (swrsList1.isEmpty() || swrsList1.size() == 1) {
            swrsList1.clear();
            swrsList1.addAll(swrsList3);
        }
        dataMap.put("今年", type.equals("sg") ? sgslList1 : swrsList1);
        dataMap.put("去年", type.equals("sg") ? sgslList2 : swrsList2);
        return dataMap;
    }

    /**
     * 在缓存中取得各个动态数据指标的最新数据
     *
     * @param cacheKey 缓存的键名
     * @return 最新数据
     */
    private Long getDynamicDataByCache(String cacheKey, String index) {
        Map<String, Object> data     = MapUtil.newHashMap();
        Map<String, Object> cacheMap = CacheUtils.get(DataScreenUtils.CACHE_NAME_SCREEN_DYNAMIC, cacheKey);
        // 最新的值、步长
        long lastData, nextIndex, difference;
        // 缓存存入时间、系统当前时间
        Date lastDate = DateUtil.date();
        Date nowDate  = DateUtil.date();
        // 时间的差值
        long td;
        // 权重值
        int weightValue;
        if (cacheMap == null || cacheMap.isEmpty()) {
            if ("1".equals(index)) {
                // 综合概览-运行动态-当前在网车辆(动态指标)
                // 畅行高速-高速运行-当前在网车辆(动态指标)
                data = dataScreenService.getNetWorkFlowData();
            } else if ("2".equals(index)) {
                // 综合概览-运行动态-当天高速车流量(动态指标)
                // 畅行高速-高速运行-累计车流量(动态指标)
                data = dataScreenService.getHighWayFlowData();
            } else if ("3".equals(index)) {
                // 综合概览-运行动态-公交客流量(动态指标)
                // 运输服务-公共交通-每日公交客流量-(动态指标-公交)
                data = dataScreenService.getBusFlowData();
            } else if ("4".equals(index)) {
                // 畅行高速-高速运行-外省入渝车流量(动态指标)
                data = dataScreenService.getProvincialFlowData();
            } else if ("5".equals(index)) {
                // 综合概览-运行动态-轨道交通总客流(动态指标)
                data = dataScreenService.getRailTransitFlowData();
            }
            // 最新的值
            lastData = Long.parseLong(data.get("lastData").toString());
            // 差值
            difference = (long) (Long.parseLong(data.get("difference").toString()) * 0.6);
            // 步长
            nextIndex = (int) Math.ceil((double) difference / 600) + 6;
            // 缓存存入时间
            data.put("lastDate", nowDate);
            CacheUtils.put(DataScreenUtils.CACHE_NAME_SCREEN_DYNAMIC, cacheKey, data);
        } else {
            // 最新的值
            lastData = Long.parseLong(cacheMap.get("lastData").toString());
            // 数据的差值
            difference = (long) (Long.parseLong(cacheMap.get("difference").toString()) * 0.6);
            // 步长
            nextIndex = (int) Math.ceil((double) difference / 600) + 6;
            // 缓存存入时间
            lastDate = (Date) cacheMap.get("lastDate");
        }
        if (index.equals("1")) {
            // 当前在网车辆
            td          = RandomUtil.randomInt(-5, 10);
            weightValue = RandomUtil.randomInt(0, 2);
        } else {
            // 其他
            td          = (nowDate.getTime() - lastDate.getTime()) / 1000;
            weightValue = RandomUtil.randomInt(1, 2);
        }
        lastData = lastData + nextIndex * (td + weightValue);
        return lastData;
    }

    /**
     * 安全应急-平安交通指数-年度事故信息(指标)
     *
     * @return 结果
     */
    @RequestMapping("getAnnualAccidentDeathData")
    @ResponseBody
    @ApiOperation("安全应急-平安交通指数-年度事故数据信息(指标)")
    public Result<?> getAnnualAccidentDeathData() {
        Map<String, Object> data = CacheUtils.get(DataScreenUtils.CACHE_NAME_SCREEN_LIST, "CACHE_KEY_ANNUAL_ACCIDENT_DEATH_DATA");
        if (data == null || data.isEmpty()) {
            data = MapUtil.newHashMap();
            data.put("data", dataScreenService.getAnnualAccidentDeathData());
            CacheUtils.put(DataScreenUtils.CACHE_NAME_SCREEN_LIST, "CACHE_KEY_ANNUAL_ACCIDENT_DEATH_DATA", data);
        }
        return Result.OK(Boolean.TRUE, "查询成功！", data);
    }

    @RequestMapping("clearCache")
    @ResponseBody
    @ApiOperation("清除指标缓存")
    public Result<?> clearCache() {
        DataScreenUtils.clearCache();
        return Result.OK(Boolean.TRUE, "清除缓存成功！", null);
    }

    @RequestMapping("getInfrastructureCountData")
    @ResponseBody
    @ApiOperation("综合概述-现状能力-基础设施(指标)")
    public Result<?> getInfrastructureCountData() {
        List<Map<String, Object>> data = CacheUtils.get(DataScreenUtils.CACHE_NAME_SCREEN_LIST, "CACHE_KEY_INFRASTRUCTURE_COUNT_DATA");
        if (data == null || data.isEmpty()) {
            data = new ArrayList<>(dataScreenService.getTargetDataByIds("1", "4"));
            Map<String, Object> map = MapUtil.newHashMap();
            map.put("name", "邮政网点数");
            map.put("value", dataScreenService.getPostalCountData());
            map.put("unit", "个");
            data.add(map);
            data.addAll(dataScreenService.getTargetDataById("6"));
            CacheUtils.put(DataScreenUtils.CACHE_NAME_SCREEN_LIST, "CACHE_KEY_INFRASTRUCTURE_COUNT_DATA", data);
        }
        return Result.OK(Boolean.TRUE, "查询成功！", data);
    }

    /**
     * 运输服务-客运服务-水路客运运行信息-三峡游客运量、朝天门两江游客运量(动态)
     * 综合概览-运行动态-三峡游客运量、朝天门两江游客运量(动态)
     */
    @RequestMapping("getWaterWayPassengerData")
    @ResponseBody
    @ApiOperation("运输服务-客运服务-水路客运运行信息-三峡游客运量、朝天门两江游客运量(动态)")
    public Result<?> getWaterWayPassengerData() {
        // 三峡游客运量
        Map<String, Object> m1 = MapUtil.newHashMap();
        m1.put("name", "三峡游客运量");
        m1.put("unit", "人次");
        m1.put("data", getPassengerVolumeDataByCache(DataScreenUtils.CACHE_KEY_YEAR_SANXIA_PASSENGER_DATA, "1", "3"));
        // 朝天门两江游客运量
        Map<String, Object> m2 = MapUtil.newHashMap();
        m2.put("name", "朝天门两江游客运量");
        m2.put("unit", "人次");
        m2.put("data", getPassengerVolumeDataByCache(DataScreenUtils.CACHE_KEY_YEAR_LIANGJIANG_PASSENGER_DATA, "2", "3"));

        List<Map<String, Object>> list = new ArrayList<>(dataScreenService.getTargetDataByIds("66", "67"));
        list.add(m1);
        list.add(m2);
        return Result.OK(Boolean.TRUE, "查询成功！", list);
    }

    /**
     * 获取三峡游客运量、朝天门两江游客运量指标数据
     *
     * @param cacheKey 缓存key值
     * @param index    下标(1:三峡游客运量,2:朝天门两江游客运量)
     * @param tjwdfl   查询条件(1:当日；3:年度)
     */
    private Long getPassengerVolumeDataByCache(String cacheKey, String index, String tjwdfl) {
        // 最新的值、步长
        long lastData, nextIndex, difference;
        // 缓存存入时间、系统当前时间
        Date lastDate, nowDate = DateUtil.date();
        // 时间的差值
        long                td       = 0L;
        Map<String, Object> cacheMap = CacheUtils.get(DataScreenUtils.CACHE_NAME_SCREEN_DYNAMIC, cacheKey);
        if (cacheMap == null || cacheMap.isEmpty()) {
            Map<String, Object> data = MapUtil.newHashMap();
            if (index.equals("1")) {
                // 三峡游客运量
                data = dataScreenService.getSanXiaPassengerData(tjwdfl);
            } else if (index.equals("2")) {
                // 朝天门两江游客运量
                if (tjwdfl.equals("1")) {
                    // 当日
                    data = dataScreenService.getLiangJiangPassengerData();
                } else if (tjwdfl.equals("3")) {
                    // 年度
                    data = dataScreenService.getLiangJiangYearPassengerData();
                }
            }
            // 最新的值
            lastData = Double.valueOf(Double.parseDouble(data.get("lastData").toString())).longValue();
            // 差值
            difference = Double.valueOf(Double.parseDouble(data.get("difference").toString())).longValue();
            // 缓存存入时间
            data.put("lastDate", nowDate);
            // 步长
            nextIndex = (int) Math.ceil((double) difference / 300) + 6;
            CacheUtils.put(DataScreenUtils.CACHE_NAME_SCREEN_DYNAMIC, cacheKey, data);
        } else {
            // 最新的值
            lastData = Double.valueOf(Double.parseDouble(cacheMap.get("lastData").toString())).longValue();
            // 缓存存入时间
            lastDate = (Date) cacheMap.get("lastDate");
            // 时间的差值
            td = (nowDate.getTime() - lastDate.getTime()) / 1000;
            // 数据的差值
            difference = Double.valueOf(Double.parseDouble(cacheMap.get("difference").toString())).longValue();
            // 步长
            nextIndex = (int) Math.ceil((double) difference / 300) + 6;
        }
        return (lastData + nextIndex * (td + RandomUtil.randomInt(-2, 2)));
    }

    @RequestMapping("getRoadWayPassengerData")
    @ResponseBody
    @ApiOperation("运输服务-客运服务-道路客运运行信息(指标)")
    public Result<?> getRoadWayPassengerData() {
        List<Map<String, Object>> list = new ArrayList<>();
        // 班线条数
        Map<String, Object> bx = MapUtil.newHashMap();
        bx.put("name", "班线条数");
        bx.put("data", dataScreenService.getRoadWayPassengerData("yunli"));
        bx.put("unit", "条");
        // 班次
        Map<String, Object> bc = MapUtil.newHashMap();
        bc.put("name", "班次");
        bc.put("data", dataScreenService.getRoadWayPassengerData("liner_count"));
        bc.put("unit", "次");
        // 总客流
        Map<String, Object> zkl = MapUtil.newHashMap();
        zkl.put("name", "总客流");
        zkl.put("data", dataScreenService.getRoadWayPassengerData("check_num"));
        zkl.put("unit", "人次");
        list.add(bx);
        list.add(bc);
        list.add(zkl);
        return Result.OK(Boolean.TRUE, "查询成功！", list);
    }

    @RequestMapping("getPostalCurrentData")
    @ResponseBody
    @ApiOperation("数字邮政-邮政现状-机构设备、基础网络(指标)")
    public Result<?> getPostalCurrentData() {
        List<Map<String, Object>> list = new ArrayList<>();
        // 邮政网点数
        Map<String, Object> wd = MapUtil.newHashMap();
        wd.putIfAbsent("name", "邮政网点数");
        wd.put("data", dataScreenService.getPostalCountData());
        wd.put("unit", "个");
        // 快递网点数
        Map<String, Object> kd = MapUtil.newHashMap();
        kd.put("name", "快递网点数");
        kd.put("data", dataScreenService.getExpressCountData("fwspmechanisms_kdoutlets"));
        kd.put("unit", "个");
        // 信筒信箱
        Map<String, Object> xx = MapUtil.newHashMap();
        xx.put("name", "信筒信箱");
        xx.put("data", dataScreenService.getExpressCountData("fwspmechanisms_mailbox"));
        xx.put("unit", "个");

        // 邮路条数（全市）
        Map<String, Object> ts = MapUtil.newHashMap();
        ts.put("name", "邮路条数（全市）");
        ts.put("data", dataScreenService.getExpressCountData("fwsproutes_allroute"));
        ts.put("unit", "条");
        // 邮路总长度（全市）
        Map<String, Object> cd = MapUtil.newHashMap();
        cd.put("name", "邮路总长度（全市）");
        cd.put("data", dataScreenService.getExpressCountData("fwsproutes_alllength"));
        cd.put("unit", "公里");

        list.add(wd);
        list.add(kd);
        list.add(xx);
        // 新能源车辆
        list.addAll(dataScreenService.getTargetDataById("220"));
        list.add(ts);
        list.add(cd);

        return Result.OK(Boolean.TRUE, "查询成功！", list);
    }

    @RequestMapping("getPostalOperationData")
    @ResponseBody
    @ApiOperation("数字邮政-行业运行(指标)")
    public Result<?> getPostalOperationData() {
        List<Map<String, Object>> data = CacheUtils.get(DataScreenUtils.CACHE_NAME_SCREEN_LIST, "CACHE_KEY_POSTAL_OPERATION_DATA");
        if (data == null || data.isEmpty()) {
            // 邮政行业业务收入
            Map<String, Object> m1 = MapUtil.newHashMap();
            m1.put("name", "邮政行业业务收入");
            m1.put("data", dataScreenService.getPostalOperationData("yzsrsrlj"));
            m1.put("unit", "亿元");
            // 邮政行业寄递业务量
            Map<String, Object> m2 = MapUtil.newHashMap();
            m2.put("name", "邮政行业寄递业务量");
            m2.put("data", dataScreenService.getPostalOperationData("yzjdsrlj"));
            m2.put("unit", "万件");
            // 同城快递业务量
            Map<String, Object> m3 = MapUtil.newHashMap();
            m3.put("name", "同城快递业务量");
            m3.put("data", dataScreenService.getPostalOperationData("tclj"));
            m3.put("unit", "万件");
            data = new ArrayList<>();
            data.add(m1);
            data.add(m2);
            data.add(m3);
            CacheUtils.put(DataScreenUtils.CACHE_NAME_SCREEN_LIST, "CACHE_KEY_POSTAL_OPERATION_DATA", data);
        }
        return Result.OK(Boolean.TRUE, "查询成功！", data);
    }

    @RequestMapping("getApprovalEventCountData")
    @ResponseBody
    @ApiOperation("行业智治-审批信用-审批-事项统计(指标)")
    public Result<?> getApprovalEventCountData() {
        List<Map<String, Object>> list = new ArrayList<>();
        // 市级事项总数
        Map<String, Object> m1 = MapUtil.newHashMap();
        m1.put("name", "市级事项总数");
        m1.put("unit", "项");
        m1.put("data", dataScreenService.getApprovalEventCountData("sjsxzs"));
        list.add(m1);
        // 市级行政许可
        Map<String, Object> m2 = MapUtil.newHashMap();
        m2.put("name", "市级行政许可");
        m2.put("unit", "项");
        m2.put("data", dataScreenService.getApprovalEventCountData("sjxzxk"));
        list.add(m2);
        // 市级非行政许可权力、市级公共服务
        list.addAll(dataScreenService.getTargetDataByIds("126", "127"));
        // 区县事项总数
        Map<String, Object> m3 = MapUtil.newHashMap();
        m3.put("name", "区县事项总数");
        m3.put("unit", "项");
        m3.put("data", dataScreenService.getApprovalEventCountData("qxsxzs"));
        list.add(m3);
        // 区县行政许可
        Map<String, Object> m4 = MapUtil.newHashMap();
        m4.put("name", "区县行政许可");
        m4.put("unit", "项");
        m4.put("data", dataScreenService.getApprovalEventCountData("qxxzxk"));
        list.add(m4);
        // 区县非行政许可权力、区县公共服务
        list.addAll(dataScreenService.getTargetDataByIds("130", "131"));

        return Result.OK(Boolean.TRUE, "查询成功！", list);
    }

    @RequestMapping("getMarketOverviewData")
    @ResponseBody
    @ApiOperation("畅行高速-高速建设-从业单位、从业人员(指标)")
    public Result<?> getMarketOverviewData() {
        List<Map<String, Object>> list = new ArrayList<>();
        // 建设单位
        list.add(dataScreenService.getMarketOverviewData("建设管理单位"));
        // 设计企业
        list.add(dataScreenService.getMarketOverviewData("设计企业"));
        // 施工企业
        list.add(dataScreenService.getMarketOverviewData("施工企业"));
        // 监理企业
        list.add(dataScreenService.getMarketOverviewData("监理企业"));
        // 非试验检测
        Map<String, Object> m1 = MapUtil.newHashMap();
        m1.put("name", "非试验检测");
        m1.put("data", dataScreenService.getMarketOverviewData3());
        list.add(m1);
        // 试验检测
        Map<String, Object> m2 = MapUtil.newHashMap();
        m2.put("name", "试验检测");
        m2.put("data", dataScreenService.getMarketOverviewData2());
        list.add(m2);
        // 工程技术人员
        list.add(dataScreenService.getMarketOverviewData("工程技术人员"));
        // 安全部门负责人
        list.add(dataScreenService.getMarketOverviewData("安全部门负责人"));
        // 技术负责人
        list.add(dataScreenService.getMarketOverviewData("技术负责人"));
        // 勘察设计人员
        list.add(dataScreenService.getMarketOverviewData("勘察设计人员"));
        // 质量部门负责人
        list.add(dataScreenService.getMarketOverviewData("质量部门负责人"));
        // 其他
        list.add(dataScreenService.getMarketOverviewData("无"));

        return Result.OK(Boolean.TRUE, "查询成功！", list);
    }

    @RequestMapping("getJiangbeiAirportData")
    @ResponseBody
    @ApiOperation("综合概览-运行动态-江北机场登机人数、江北机场起飞航班数(动态)")
    public Result<?> getJiangbeiAirportData() {
        // 江北机场登机人数
        Map<String, Object> m1 = MapUtil.newHashMap();
        m1.put("name", "江北机场登机人数");
        m1.put("unit", "人次");
        m1.put("data", getJiangbeiAirportDataByCache(DataScreenUtils.CACHE_KEY_CURRENT_JIANGBEI_BOARD_DATA, "1"));
        // 朝天门两江游客运量
        Map<String, Object> m2 = MapUtil.newHashMap();
        m2.put("name", "江北机场起飞航班数");
        m2.put("unit", "架次");
        m2.put("data", dataScreenService.getJiangBeiQifeiCountData());

        List<Map<String, Object>> list = new ArrayList<>();
        list.add(m1);
        list.add(m2);
        return Result.OK(Boolean.TRUE, "查询成功！", list);
    }

    /**
     * 获取江北机场登机人数、江北机场起飞航班数(动态)
     *
     * @param cacheKey 缓存Key
     * @param type     类型（1：当天；2：当年累计）
     */
    private Long getJiangbeiAirportDataByCache(String cacheKey, String type) {
        // 最新的值、步长
        long lastData, nextIndex, difference;
        // 缓存存入时间、系统当前时间
        Date lastDate, nowDate = DateUtil.date();
        // 时间的差值
        long                td       = 0L;
        Map<String, Object> cacheMap = CacheUtils.get(DataScreenUtils.CACHE_NAME_SCREEN_DYNAMIC, cacheKey);
        if (cacheMap == null || cacheMap.isEmpty()) {
            long value = getValue(type);
            // 最新的值
            lastData = value;
            // 差值
            difference = value / 10000;
            // 缓存存入时间
            Map<String, Object> data = MapUtil.newHashMap();
            data.put("lastData", value);
            data.put("lastDate", nowDate);
            data.put("difference", difference);
            // 步长
            nextIndex = (int) Math.ceil((double) difference / 300);
            CacheUtils.put(DataScreenUtils.CACHE_NAME_SCREEN_DYNAMIC, cacheKey, data);
        } else {
            // 最新的值
            lastData = Long.parseLong(cacheMap.get("lastData").toString());
            // 缓存存入时间
            lastDate = (Date) cacheMap.get("lastDate");
            // 时间的差值
            td = (nowDate.getTime() - lastDate.getTime()) / 1000;
            // 数据的差值
            difference = Long.parseLong(cacheMap.get("difference").toString());
            // 步长
            nextIndex = (int) Math.ceil((double) difference / 300);
        }
        return (lastData + nextIndex * (td + RandomUtil.randomInt(0, 1)));
    }

    private long getValue(String type) {
        long value;
        if (type.equals("1")) {
            // 当天江北机场登机人数
            value = dataScreenService.getJiangBeiDengjiCountData();
        } else {
            // 年度累计江北机场登机人数
            value = dataScreenService.getJiangBeiDengjiYearCountData();
        }
        return value;
    }

    @RequestMapping("getSanxiaLiangjiangData")
    @ResponseBody
    @ApiOperation("综合概览-运行动态-三峡游客运量、朝天门两江游客运量(动态)")
    public Result<?> getSanxiaLiangjiangData() {
        // 三峡游客运量
        Map<String, Object> m1 = MapUtil.newHashMap();
        m1.put("name", "三峡游客运量");
        m1.put("unit", "人次");
        m1.put("data", getPassengerVolumeDataByCache(DataScreenUtils.CACHE_KEY_CURRENT_SANXIA_PASSENGER_DATA, "1", "1"));
        // 朝天门两江游客运量
        Map<String, Object> m2 = MapUtil.newHashMap();
        m2.put("name", "朝天门两江游客运量");
        m2.put("unit", "人次");
        m2.put("data", getPassengerVolumeDataByCache(DataScreenUtils.CACHE_KEY_CURRENT_LIANGJIANG_PASSENGER_DATA, "2", "1"));

        List<Map<String, Object>> list = new ArrayList<>();
        list.add(m1);
        list.add(m2);
        return Result.OK(Boolean.TRUE, "查询成功！", list);
    }

    @RequestMapping("getJiangBeiTabData")
    @ResponseBody
    @ApiOperation("数字民航-民航现状-机场体系-江北机场(指标)")
    public Result<?> getJiangBeiTabData() {
        // 当日起飞航班数
        Map<String, Object> m1 = MapUtil.newHashMap();
        m1.put("name", "当日起飞航班数");
        m1.put("unit", "架次");
        m1.put("data", dataScreenService.getJiangBeiQifeiCountData());
        // 年累计起飞航班数
        Map<String, Object> m2 = MapUtil.newHashMap();
        m2.put("name", "年累计起飞航班数");
        m2.put("unit", "架次");
        m2.put("data", dataScreenService.getJiangBeiQifeiYearCountData());
        // 当日登机人数
        Map<String, Object> m3 = MapUtil.newHashMap();
        m3.put("name", "当日登机人数");
        m3.put("unit", "人次");
        m3.put("data", getJiangbeiAirportDataByCache(DataScreenUtils.CACHE_KEY_CURRENT_JIANGBEI_BOARD_DATA, "1"));
        // 年累计登机人数
        Map<String, Object> m4 = MapUtil.newHashMap();
        m4.put("name", "年累计登机人数");
        m4.put("unit", "人次");
        m4.put("data", getJiangbeiAirportDataByCache(DataScreenUtils.CACHE_KEY_YEAR_JIANGBEI_BOARD_DATA, "2"));

        List<Map<String, Object>> list = new ArrayList<>();
        list.add(m1);
        list.add(m2);
        list.add(m3);
        list.add(m4);
        return Result.OK(Boolean.TRUE, "查询成功！", list);
    }

    @RequestMapping("getVehicleDetectionData")
    @ResponseBody
    @ApiOperation("行业智治-综合执法-公路治超-检测车辆总数(动态)")
    public Result<?> getVehicleDetectionData() {
        List<Map<String, Object>> list = new ArrayList<>();
        // 当日起飞航班数
        Map<String, Object> m1 = MapUtil.newHashMap();
        m1.put("name", "检测车辆总数");
        m1.put("unit", "台次");
        m1.put("data", getVehicleDetectionByCache());
        list.add(m1);
        return Result.OK(Boolean.TRUE, "查询成功！", list);
    }

    /**
     * 检测车辆总数(动态)
     */
    private Long getVehicleDetectionByCache() {
        // 最新的值、步长
        long lastData, nextIndex, difference;
        // 缓存存入时间、系统当前时间
        Date lastDate, nowDate = DateUtil.date();
        // 时间的差值
        long                td       = 0L;
        Map<String, Object> cacheMap = CacheUtils.get(DataScreenUtils.CACHE_NAME_SCREEN_DYNAMIC, "CACHE_KEY_VEHICLE_DETECTION");
        if (cacheMap == null || cacheMap.isEmpty()) {
            Map<String, Object> data = dataScreenService.getVehicleDetectionData();
            // 最新的值
            lastData = Long.parseLong(data.get("lastData").toString());
            // 差值
            difference = (long) Math.ceil(Long.parseLong(data.get("difference").toString()) * 0.8);
            // 缓存存入时间
            data.put("lastDate", nowDate);
            // 步长
            nextIndex = (int) Math.ceil((double) difference / 300) + 1;
            CacheUtils.put(DataScreenUtils.CACHE_NAME_SCREEN_DYNAMIC, "CACHE_KEY_VEHICLE_DETECTION", data);
        } else {
            // 最新的值
            lastData = Long.parseLong(cacheMap.get("lastData").toString());
            // 缓存存入时间
            lastDate = (Date) cacheMap.get("lastDate");
            // 时间的差值
            td = (nowDate.getTime() - lastDate.getTime()) / 1500;
            // 数据的差值
            difference = (long) Math.ceil(Long.parseLong(cacheMap.get("difference").toString()) * 0.8);
            // 步长
            nextIndex = (int) Math.ceil((double) difference / 300) + 1;
        }
        return (lastData + nextIndex * (td + RandomUtil.randomInt(-2, 2)));
    }

    @RequestMapping("getJiangBeiTabChartData")
    @ResponseBody
    @ApiOperation("数字民航-民航现状-机场体系-江北机场-月度起飞航班数、月度登机人数(柱形图)")
    public Result<?> getJiangBeiTabChartData() {
        Map<String, Object> dataMap = CacheUtils.get(DataScreenUtils.CACHE_NAME_SCREEN_LIST, "CACHE_KEY_JIANGBEI_TAB_CHART_DATA");
        if (dataMap == null || dataMap.isEmpty()) {
            dataMap = MapUtil.newHashMap();
            // 月度起飞航班数 柱形图
            List<Map<String, String>> list = dataScreenService.getQifeiCountMonthData();
            // 得到xAxis和data
            List<Object> xAxis = new ArrayList<>();
            List<Object> data  = new ArrayList<>();
            for (Map<String, String> map : list) {
                String name  = map.get("name");
                Object value = map.get("value");
                if (name != null) {
                    xAxis.add(name);
                }
                if (value != null) {
                    data.add(value);
                }
            }
            Map<String, Object> qifei = MapUtil.newHashMap();
            qifei.put("xAxis", xAxis);
            qifei.put("data", data);
            qifei.put("name", "起飞航班数");
            qifei.put("unit", "架次");
            dataMap.put("qifei", qifei);

            // 月度登机人数 柱形图
            List<Map<String, String>> list2 = dataScreenService.getDengjiCountMonthData();
            // 得到xAxis和data
            List<Object> xAxis2 = new ArrayList<>();
            List<Object> data2  = new ArrayList<>();
            for (Map<String, String> map : list2) {
                String name  = map.get("name");
                Object value = map.get("value");
                if (name != null) {
                    xAxis2.add(name);
                }
                if (value != null) {
                    data2.add(value);
                }
            }
            Map<String, Object> dengji = MapUtil.newHashMap();
            dengji.put("xAxis", xAxis2);
            dengji.put("data", data2);
            dengji.put("name", "登机人数");
            dengji.put("unit", "人次");
            dataMap.put("dengji", dengji);

            CacheUtils.put(DataScreenUtils.CACHE_NAME_SCREEN_LIST, "CACHE_KEY_JIANGBEI_TAB_CHART_DATA", dataMap);
        }
        return Result.OK(Boolean.TRUE, "查询成功！", dataMap);
    }


}
